// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
// 引用组件
import Vue from 'vue'
import App from './App'
import router from './router'
import http from './utils/http'
// import axios from 'axios'
import elementui from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import store from './utils/store'
import qs from 'qs'

Vue.config.productionTip = false

// 定义vue的属性
// Vue.prototype.$axios = axios
Vue.prototype.$http = http
Vue.prototype.$store = store
Vue.prototype.$qs = qs

/* 每次路径跳转之前运行 next()函数:向下执行 */
router.beforeEach((newRouter, oldRouter, next) => {
  let token = sessionStorage.getItem('token')
  // 已经登录，访问的是登录
  if (newRouter.name === 'Login' || token) {
    console.log('已经登录')
    next()
  } else {
    // 如果没有登录
    console.log('未登录')
    next('/')
  }
})

Vue.use(elementui)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
